import java.util.Scanner;

public class Knapsack {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int N = 1010;
        int n, V;
        int[] v = new int[N], w = new int[N];
        int[][] dp = new int[N][N];

        // Input
        n = sc.nextInt();
        V = sc.nextInt();

        for (int i = 1; i <= n; i++) {
            v[i] = sc.nextInt();
            w[i] = sc.nextInt();
        }

        // First part of the problem (0/1 Knapsack DP)
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= V; j++) {
                dp[i][j] = dp[i - 1][j];
                if (j >= v[i]) {
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
                }
            }
        }

        System.out.println(dp[n][V]);

        // Reset dp for the second part of the problem
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                dp[i][j] = 0;
            }
        }

        // Initialize the second part of the DP (Negative values to represent impossible states)
        for (int j = 1; j <= V; j++) {
            dp[0][j] = -1;
        }

        // Second part of the problem
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= V; j++) {
                dp[i][j] = dp[i - 1][j];
                if (j >= v[i] && dp[i - 1][j - v[i]] != -1) {
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
                }
            }
        }

        System.out.println(dp[n][V] == -1 ? 0 : dp[n][V]);
    }
}
